/*************************************************************************
	> File Name: 001.kmp.cpp
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 二  2/23 17:27:48 2021
 ************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int getNextArray(const char *t, int &j, char input, int *next) {
    while (j != -1 && t[j + 1] - input) j = next[j];
    if (t[j + 1] == input) j += 1;
    return j;
}

int kmp(const char *s, const char *t) {
    int len = strlen(t);
    int *next = (int *)malloc(sizeof(int) * (len + 1));
    next[0] = -1;
    for (int i = 0, j = -1; t[i]; i++) next[i] = getNextArray(t, j, t[i], next);
    for (int i = 0, j = -1; s[i]; i++) {
        if (getNextArray(t, j, s[i], next) != (len - 1)) continue;
        return i - len + 1;
    }
    free(next);
    return -1;
}

int main() {
    char s[100], t[100];
    while (~scanf("%s%s", s, t)) {
        printf("kmp(%s, %s) = %d\n", s, t, kmp(s, t));
    }

    return 0;
}
